package com.android.Hello;

import java.util.ArrayList;
import java.util.List;

import android.R.integer;
import android.R.string;
import android.app.Activity;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioGroup;
import android.widget.Spinner;

public class ActivityWidget extends Activity implements OnClickListener
{
	CheckBox ck_plain;
	CheckBox ck_serif;
	CheckBox ck_italic;
	CheckBox ck_bold;
	RadioGroup rg0;

	Spinner spinner1;
	Spinner spinner2;
	ArrayAdapter<String> aspnCountries;
	List<String> allCountries;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentView(R.layout.widget);
		find_and_modify_textview();

		rg0 = (RadioGroup) findViewById(R.id.radioGroup1);
		Button btn1 = (Button) findViewById(R.id.button2);
		btn1.setOnClickListener(this);
	}

	private void find_and_modify_textview()
	{
		ck_plain = (CheckBox) findViewById(R.id.checkBox1);
		ck_serif = (CheckBox) findViewById(R.id.checkBox2);
		ck_italic = (CheckBox) findViewById(R.id.checkBox3);
		ck_bold = (CheckBox) findViewById(R.id.checkBox4);

		Button btn = (Button) findViewById(R.id.button1);
		btn.setOnClickListener(getbtnlistener);

		spinner1 = (Spinner) findViewById(R.id.spinner1);
		allCountries = new ArrayList<String>();
		for(int i= 0 ;i<mCountries.length ;i++)
		{
			allCountries.add(mCountries[i]);
		}
		aspnCountries = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,allCountries);
		aspnCountries.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner1.setAdapter(aspnCountries);
		
		spinner2 = (Spinner)findViewById(R.id.spinner2);
		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource
				(this,R.array.countries ,android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner2.setAdapter(adapter);
	}

	private Button.OnClickListener getbtnlistener = new Button.OnClickListener()
	{

		@Override
		public void onClick(View v)
		{
			// TODO Auto-generated method stub
			String r = "";
			if (ck_plain.isChecked())
			{
				r += "," + ck_plain.getText();

			}
			if (ck_serif.isChecked())
			{
				r += "," + ck_serif.getText();
			}
			if (ck_italic.isChecked())
			{
				r += "," + ck_italic.getText();
			}
			if (ck_bold.isChecked())
			{
				r += "," + ck_bold.getText();
			}
			setTitle("checked " + r);
		}
	};

	public void onClick(View v)
	{
		rg0.clearCheck();
	}

	private static final String[] mCountries = { "China", "Russia", "Germany",
			"Ukraine", "Belarus", "USA" };

}
